<template>
	<view class="productItem" @click="goDetail">
		<view class="product-box">
			<view class="product-img-wrapper">
				<image :src="source.productImage" mode="aspectFill" class="product-img"></image>
				<image :src="source.labelImage" class="label-img" mode="widthFix"></image>
				<view class="inventory">
					库存:{{ source.inventory }}
				</view>
				<text class="product-code">货号:{{ source.productCode }}</text>
			</view>
			<view class="product-info-wrapper">
				<view class="title-wrapper">
					<view class="title">
						{{ source.productName }}
					</view>
					<uni-icons type="right" size="16" color="#acacac"></uni-icons>
				</view>
				<view class="info-tag" v-if="source.moq > 1 || source.loq || source.multiple > 1" @click="goDetail">
					<view v-if="source.multiple > 1" class="tag">
						倍数:{{ source.multiple }}
					</view>
					<view v-if="source.moq > 1" class="tag">
						起订:{{ source.moq }}
					</view>
					<view v-if="source.loq" class="tag">
						限购:{{ source.loq }}
					</view>
				</view>
				<view class="info-wrapper">
					<view class="info">
						净重:约{{ source.netWeight }}斤 | 净单价:约{{ (source.sellingPrice/source.netWeight).toFixed(1) }}元/斤
					</view>
					<view class="info">
						毛重:约{{ source.grossWeight }}斤 |
						毛单价:约{{ (source.sellingPrice/source.grossWeight).toFixed(1) }}元/斤
					</view>
				</view>
				<view class="price-wrapper">
					<view class="price">
						<text class="normal">￥</text>
						<text class="number">{{ source.sellingPrice }}</text>
						<text class="unit">/件</text>
					</view>
					<!-- <view class="add-wrapper" :class="{'disabled': !source.inventory}" @click.stop="openAdd">
					<view class="text" v-if="source.number > 0">
						已选{{ source.number }}件
					</view>
					<view class="add">
						<uni-icons type="plusempty" color="#fff" size="14" class="icons"></uni-icons>
					</view>
				</view> -->
					<view class="status-wrapper" @click.stop="empty">
						<switch @change="statusChange" :checked="source.show" color="#F26022"
							style="transform:scale(0.7)" />
						<text class="text">{{ source.show ? '展示' : '屏蔽' }}</text>
					</view>
				</view>
				<view class="sales-volume">
					<text>近30天销售</text>
					<text class="volume">{{ source.salesVolume }}件</text>
				</view>
			</view>
		</view>
		<view class="label-wrapper" v-if="source.labelList && source.labelList.length">
			<view class="label-item" v-for="(item,index) in source.labelList" :key="index"
				:style="{'color':item.labelColor,'background-color':item.labelColor + '11','border-color': item.labelColor}">
				{{ item.labelName }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			source: {
				type: Object,
				default: () => ({})
			},
		},
		data() {
			return {
				show: true
			}
		},
		mounted() {

		},
		computed: {
			token() {
				return this.$store.state.token
			}
		},
		methods: {
			statusChange(e) {
				this.$emit('statusChange', e.detail.value, this.source.id)
			},
			empty() {},
			goDetail() {
				uni.navigateTo({
					url: '/subPage_product/productDetail?id=' + this.source.id
				})
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.productItem {
		padding: 24upx 24rpx 18rpx 24rpx;
		background-color: #ffffff;
		border-bottom: 2upx solid #f2f2f2;

		.product-box {
			display: flex;
		}


		.product-img-wrapper {
			position: relative;
			width: 150upx;
			height: 150upx;

			.product-img {
				width: 150upx;
				height: 150upx;
				border-radius: 14upx;
			}

			.label-img {
				position: absolute;
				top: 5rpx;
				left: 5rpx;
				width: 50rpx;
				height: 50rpx;
				z-index: 1;
			}

			.product-code {
				font-size: 22upx;
				color: #777;
			}

			.inventory {
				position: absolute;
				left: 0;
				bottom: 0;
				height: 40upx;
				width: 100%;
				background-color: rgba(0, 0, 0, 0.6);
				color: #ffffff;
				font-size: 26upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 0 0 14rpx 14upx;
			}
		}

		.product-info-wrapper {
			margin-left: 20upx;
			flex: 1;

			.title-wrapper {
				display: flex;
				align-items: center;

				.title {
					flex: 1;
					font-size: 30upx;
					color: #292929;
					line-height: 38upx;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden; //溢出内容隐藏
					text-overflow: ellipsis; //文本溢出部分用省略号表示
					display: -webkit-box; //特别显示模式
					-webkit-line-clamp: 2; //行数
					line-clamp: 2;
					-webkit-box-orient: vertical; //盒子中内容竖直排列
				}
			}

			.info-tag {
				display: flex;
				align-items: center;
				margin-top: 4rpx;

				.tag {
					font-size: 20upx;
					border: 1upx solid #cecece;
					border-radius: 5rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					height: 26rpx;
					padding: 0 10rpx;
					color: #666;
					margin-right: 20rpx;
				}
			}

			.info-wrapper {
				margin: 10upx 0;

				.info {
					margin-top: 10upx;
					font-size: 22upx;
					line-height: 22upx;
					color: #808080;
				}
			}

			.price-wrapper {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.price {
					color: #F93C21;
					font-size: 28upx;
					vertical-align: bottom;


					.number {
						font-size: 44upx;
						font-weight: bold;
					}

					.unit {
						position: relative;
						top: -4upx;
					}
				}

				.status-wrapper {
					display: flex;
					align-items: center;
					font-size: 32upx;
					color: #666666;
					position: relative;

					.text {
						margin-left: -15rpx;
					}
				}

				.add-wrapper {
					background-color: #EDF7EB;
					border-radius: 16upx;
					height: 45upx;
					display: flex;
					align-items: center;

					.text {
						flex: 1;
						margin: 0 10upx;
						font-size: 20upx;
						color: #1DB000;
					}

					.add {
						width: 45upx;
						height: 45upx;
						border-radius: 16upx;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: #1DB000;

						.icons {
							font-weight: bold;
							line-height: 22rpx;
						}
					}

					&.disabled {
						.add {
							background-color: #898899;
						}
					}
				}
			}
		}

		.sales-volume {
			font-size: 24rpx;
			color: #666;
			margin-bottom: 10rpx;
			text-align: right;

			.volume {
				color: #F93C21;
			}
		}

		.label-wrapper {
			display: flex;
			align-items: center;
			padding: 0 5rpx;
			margin-top: -15rpx;
			flex-wrap: wrap;

			.label-item {
				padding: 0rpx 10rpx;
				margin-top: 15rpx;
				font-size: 18upx;
				color: #0D8EFF;
				border: 1rpx solid #0D8EFF;
				background-color: #0D8EFF22;
				margin-right: 10rpx;
				border-radius: 5rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: center;
				height: 30rpx;
				line-height: 30rpx;
			}
		}
	}
</style>